package com.example.leetdemo.finash;

import org.springframework.util.StringUtils;

import java.util.Stack;

public class Solution1614 {

    public int maxDepth(String s) {
        if (!StringUtils.hasText(s)) {
            return 0;
        }
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(' || s.charAt(i) == ')') {
                stack.add(s.charAt(i));
            }
        }
        int max = 0;
        int now = 0;
        while (stack.size() > 0) {
            if (stack.pop() == ')') {
                now++;
            } else {
                now--;
            }
            max = Math.max(now, max);
        }
        return max;
    }

    public static void main(String[] args) {
        Solution1614 solution1614 = new Solution1614();
        System.err.println(solution1614.maxDepth("(((()))(()))"));
    }
}
